<script type="text/javascript">
    $(document).ready(function () {

        $('form').submit(function (e) {
            e.preventDefault();
            var data = 'login=' + $(this).find('.login_nick').val() +
                    '&pass=' + $(this).find('.pass').val() +
                    '&pass2=' + $(this).find('.pass2').val() +
                    '&email=' + $(this).find('.email').val();
            $.ajax({
                url:'<?php echo base_url() . "registration/register/"?>',
                type:'POST',
                data:data,
                success:function (data) {
                    obj = eval("(" + data + ")");
                    if (obj == "Ok") {
                        $('.reg_div h1').html('Registrácia bola úspešná!');
                        $('.forma').empty();
                        $(function () {
                            setTimeout(function () {
                                $('#facebox').hide();
                                $('.warn_comments').hide();
                                $('.warn_thumbs').hide();
                                $('.facebox_overlayBG').hide();
                                $('.facebox_overlay').hide();
                            }, 2000);

                        });
                    }
                    else {

                        obj = eval("(" + data + ")");
                        if (obj == "Error") {
                            if ($('.reg_error').html != "") {
                                $('.reg_error').fadeOut(500);
                                $('.reg_error').fadeIn(500);
                            }
                            $('.reg_error').html('<span style="font-size:10px; color:red;">' + "Login or e-mail is already in use." + '</span>');
                            $('.log_error').html('');
                            $('.pass_error').html('');
                            $('.pass2_error').html('');
                            $('.email_error').html('');
                        }
                        else {
                            if (obj['login'] == "") {
                                $('.log_error').html('');
                            }
                            if (obj['pass'] == "") {
                                $('.pass_error').html('');
                            }
                            if (obj['pass2'] == "") {
                                $('.pass2_error').html('');
                            }
                            if (obj['email'] == "") {
                                $('.email_error').html('');
                            }
                            if (obj['login'] != "") {
                                if ($('.log_error').html != "") {
                                    $('.log_error').fadeOut(500);
                                    $('.log_error').fadeIn(500);
                                }
                                $('.log_error').html('<span style="font-size:10px; color:red;">' + obj['login'] + '</span>');
                            }
                            if (obj['pass'] != "") {
                                if ($('.pass_error').html != "") {
                                    $('.pass_error').fadeOut(500);
                                    $('.pass_error').fadeIn(500);
                                }
                                $('.pass_error').html('<span style="font-size:10px; color:red;">' + obj['pass'] + '</span>');
                            }
                            if (obj['pass2'] != "") {
                                if ($('.pass2_error').html != "") {
                                    $('.pass2_error').fadeOut(500);
                                    $('.pass2_error').fadeIn(500);
                                }
                                $('.pass2_error').html('<span style="font-size:10px; color:red;">' + obj['pass2'] + '</span>');
                            }
                            if (obj['email'] != "") {
                                if ($('.email_error').html != "") {
                                    $('.email_error').fadeOut(500);
                                    $('.email_error').fadeIn(500);
                                }
                                $('.email_error').html('<span style="font-size:10px; color:red;">' + obj['email'] + '</span>');
                            }
                        }
                    }
                }
            });
        });

    });
</script>

<div class="reg_div">
    <h1 style='text-align: center;'>Registrácia</h1>
    <ul style="list-style: none;text-align: center;padding:3px;" class="forma">
        <?php echo form_open('registration/submit');
        ?>
        <li class="reg_error">
        </li>
        <li>
            <?php echo form_input(array('type' => 'text', 'name' => 'login', 'class' => 'login_nick', 'placeholder' => 'Login')); ?>
        </li>
        <li class="log_error">
        </li>
        <li>
            <?php echo form_input(array('type' => 'password', 'name' => 'pass', 'class' => 'pass', 'placeholder' => 'Password')); ?>
        </li>
        <li class="pass_error">
        </li>
        <li>
            <?php echo form_input(array('type' => 'password', 'name' => 'pass2', 'class' => 'pass2', 'placeholder' => 'Password again...')); ?>
        </li>
        <li class="pass2_error">
        </li>
        <li>
            <?php echo form_input(array('type' => 'text', 'name' => 'email', 'class' => 'email', 'placeholder' => 'E-mail')); ?>
        </li>
        <li class="email_error">
        </li>
        <li>
            <?php echo form_submit(array('type' => 'submit', 'value' => 'Registrovať', 'class' => 'reg_button')); ?>
        </li>
        <?php echo form_close(); ?>

    </ul>

</div>